| 1 |  |  | const lengthInput = document.getElementById("length"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | const lowercaseCb = document.getElementById("lowercase"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | const uppercaseCb = document.getElementById("uppercase"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | const numbersCb = document.getElementById("numbers"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | const symbolsCb = document.getElementById("symbols"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | const resultField = document.getElementById("result"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | const generateBtn = document.getElementById("generateBtn"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | const copyBtn = document.getElementById("copyBtn"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | const lowercase = "abcdefghijklmnopqrstuvwxyz"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | const numbers = "0123456789"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | const symbols = "!@#$%^&*()_+{}[]<>?/|"; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | function generatePassword() { | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |   let chars = ""; | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |   if (lowercaseCb.checked) chars += lowercase; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |   if (uppercaseCb.checked) chars += uppercase; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |   if (numbersCb.checked) chars += numbers; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |   if (symbolsCb.checked) chars += symbols; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |   const length = parseInt(lengthInput.value); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |   if (!chars) { | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     resultField.value = "Select at least one option!"; | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     return; | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |   } | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |   let password = ""; | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |   for (let i = 0; i < length; i++) { | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     const rand = Math.floor(Math.random() * chars.length); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     password += chars[rand]; | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |   } | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |   resultField.value = password; | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | generateBtn.addEventListener("click", generatePassword); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | copyBtn.addEventListener("click", () => { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |   if (resultField.value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     navigator.clipboard.writeText(resultField.value); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     alert("Password copied!"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 42 |  |  |   } | 
            
                                                        
            
                                    
            
            
                | 43 |  |  | }); | 
            
                        
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.